var retryTime = 1000 * 2; //2 seconds
//Pure ajax - developed by Amir
var xhrTimeout;
function receive(from_url, update_div, rqTimeout) {
    var xhr;

    if (window.XMLHttpRequest){
        xhr=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xhr=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xhr.onreadystatechange = function() {
        if ( xhr.readyState == 4 && xhr.status == 200) {
            clearTimeout(xhrTimeout);   // Looks like we didn't time out!
            updatemessage(update_div, xhr.responseText);
            setTimeout("receive('"+from_url+"','"+update_div+"',"+rqTimeout+")", retryTime);//try for next message
        }
        else if ( xhr.readyState == 4 && xhr.status == 404)
        {
            updatemessage(update_div, "Page not found");
            setTimeout("receive('"+from_url+"','"+update_div+"',"+rqTimeout+")", retryTime);//try for next message
        }
    };
    xhr.open("GET", from_url, true);
    xhr.send();
    xhrTimeout=setTimeout("ajaxTimeout('"+update_div+"','"+from_url+"',"+rqTimeout+")",rqTimeout);
}

function ajaxTimeout(update_div,from_url,rqTimeout){
    setTimeout("receive('"+from_url+"','"+update_div+"',"+rqTimeout+")", retryTime);//try again when time out occur
}

function addmessage(update_div, msg){
    var temp=document.getElementById(update_div).innerHTML;
    document.getElementById(update_div).innerHTML=temp+"<br />"+msg;
}
function updatemessage(update_div, msg){
    if(msg=='') return;
    document.getElementById(update_div).innerHTML=msg;
}
